Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add kube-linter binary #209

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

feat: add kube-linter binary #209

wants to merge 2 commits into from

Conversation

Monska85
Copy link
Contributor

@Monska85 Monska85 commented Aug 27, 2024

PR Type

Enhancement


Description

  • Added kube-linter (version 0.6.8) to the Docker image for Kubernetes manifest linting
  • Introduced a multi-stage build to compile kube-linter from source
  • Copied the kube-linter binary from the build stage to the final image
  • Set proper permissions for the kube-linter binary
  • Maintained existing functionality and versions of other tools in the image

Changes walkthrough 📝

Relevant files
Enhancement
Dockerfile
Add kube-linter to the Docker image                                           

Dockerfile

  • Added a new build stage using golang:1.23.0-alpine3.20 to install
    kube-linter
  • Set KUBELINTER_VERSION environment variable to 0.6.8
  • Installed git and kube-linter in the build stage
  • Copied kube-linter binary from the build stage to the final image
  • Set executable permissions for kube-linter
  • +12/-0   

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @paolomainardi
    Copy link
    Member

    /describe

    @paolomainardi
    Copy link
    Member

    /review

    @paolomainardi
    Copy link
    Member

    /improve

    @sparkfabrik-ai-bot
    Copy link

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ No key issues to review

    @sparkfabrik-ai-bot
    Copy link

    PR Description updated to latest commit (79806fe)

    @sparkfabrik-ai-bot
    Copy link

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Use a specific image digest for the golang base image to ensure reproducibility

    Consider using a specific version of the golang image instead of the latest patch
    version. This ensures reproducibility and prevents potential issues with future
    updates.

    Dockerfile [5]

    -FROM golang:1.23.0-alpine3.20 AS gobinaries
    +FROM golang:1.23.0-alpine3.20@sha256:1234567890abcdef AS gobinaries
     
    Suggestion importance[1-10]: 8

    Why: Using a specific image digest ensures reproducibility and prevents potential issues with future updates, which is crucial for maintaining a stable build environment.

    8
    Add a version check for the installed binary to ensure correctness

    Consider adding a version check for kube-linter after installation to ensure the
    correct version is installed and executable.

    Dockerfile [76-77]

    -COPY --from=gobinaries /go/bin/kube-linter /usr/local/bin/kube-linter
    -RUN chmod +x /usr/local/bin/kube-linter
    +COPY --from=gobinaries /go/bin/kube-linter /usr/local/bin/kube-linter && \
    +    chmod +x /usr/local/bin/kube-linter && \
    +    kube-linter version | grep -q "${KUBELINTER_VERSION}"
     
    Suggestion importance[1-10]: 8

    Why: Adding a version check after installation ensures that the correct version of kube-linter is installed and executable, which is important for maintaining consistency and catching potential installation issues.

    8
    Performance
    Use the --no-cache flag with go install to reduce image size

    Consider using the --no-cache flag with the go install command to avoid caching
    build artifacts and reduce the image size.

    Dockerfile [9-10]

     RUN apk --no-cache add git \
    -    && go install golang.stackrox.io/kube-linter/cmd/kube-linter@v${KUBELINTER_VERSION}
    +    && go install --no-cache golang.stackrox.io/kube-linter/cmd/kube-linter@v${KUBELINTER_VERSION}
     
    Suggestion importance[1-10]: 7

    Why: Using the --no-cache flag with go install can help reduce the image size by avoiding the storage of build artifacts, which is beneficial for optimizing container performance.

    7
    Combine COPY and RUN commands to reduce the number of layers in the final image

    Consider combining the RUN commands for installing kube-linter and setting
    permissions to reduce the number of layers in the final image.

    Dockerfile [76-77]

    -COPY --from=gobinaries /go/bin/kube-linter /usr/local/bin/kube-linter
    -RUN chmod +x /usr/local/bin/kube-linter
    +COPY --from=gobinaries /go/bin/kube-linter /usr/local/bin/kube-linter && \
    +    chmod +x /usr/local/bin/kube-linter
     
    Suggestion importance[1-10]: 6

    Why: Combining the COPY and RUN commands can slightly reduce the number of layers in the final image, which can marginally improve build time and image size.

    6

    @paolomainardi
    Copy link
    Member

    For me it’s a 👍

    @paolomainardi
    Copy link
    Member

    /reflect

    @sparkfabrik-ai-bot
    Copy link

    Questions to better understand the PR:

    1. Is the addition of kube-linter intended to replace any existing linting tools in the image, or is it complementary to the current setup?

    2. The PR adds kube-linter version 0.6.8. Was this specific version chosen for any particular reason, such as compatibility with other tools or specific features?

    3. How do you envision the kube-linter tool being used in the deployment pipeline? Can you briefly describe a typical use case?

    Please respond to the questions above in the following format:

    /answer

    1. ...
    2. ...
      ...

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants